package com.ilovepostcard.view;

import com.ilovepostcard.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.EditText;

public class MyEditText extends EditText {   
	   
    private Paint mPaint;   
    int mLines;
    int mLineColor;
    float mLinefactor;
    int paddingbottom;
    public MyEditText(Context context, AttributeSet attrs) {   
        super(context, attrs);   
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PostcardEditText);
        mLines = ta.getInt(R.styleable.PostcardEditText_lines, 5);
        mLinefactor = ta.getFloat(R.styleable.PostcardEditText_lineSpacingMultiplier, 1.0f);
        mLineColor =  ta.getColor(R.styleable.PostcardEditText_linecolor, R.color.color_title);
        paddingbottom =  ta.getInt(R.styleable.PostcardEditText_paddingBottom, 10);
        mPaint = new Paint();   
           
        mPaint.setStyle(Paint.Style.STROKE);   
        mPaint.setColor(mLineColor);   
        
        ta.recycle();
    }   
       
    @Override   
    public void onDraw(Canvas canvas)   
    {

          int lineHeight=this.getLineHeight();
          int count = mLines;
          if(count<1)
        	  count = getHeight()/lineHeight;
          int topPadding=this.getPaddingTop();
          int leftPadding=this.getPaddingLeft();
          float textSize=getTextSize();
          setGravity(Gravity.LEFT|Gravity.TOP);
          int y=(int)(topPadding+textSize);
          
          for(int i=0;i<count;i++){
              canvas.drawLine(leftPadding,y+paddingbottom,getRight()-leftPadding,y+paddingbottom,mPaint);
              y+=lineHeight;
              }
          canvas.translate(0,0);
          super.onDraw(canvas);
		}   

}   
